﻿using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using zic_dotnet;
using zic_dotnet.Domain;

namespace stackFluent.Domain {
    public class User : IAggregateRoot {
        [Key]
        public Guid ID { get; set; }

        public int ActId { get; set; }
        public int RoleId { get; set; }

        //不但作为登录ID，也作为个人信息的重要部分
        [Required]
        [MaxLength(100)]
        public string Email { get; set; }

        [Required]
        [Column("Password")]
        [MaxLength(128)]
        public string PasswordHash { get; set; }
        public string Password {
            set { PasswordHash = EncryptPassword(value); }
        }

        public bool EqualsPassword(string value) {
            return this.PasswordHash.Equals(EncryptPassword(value));
        }
        public static string EncryptPassword(string value) {
            return Encrypt.EncryptUserPassword(value);
        }

        [MaxLength(50)]
        public string Name { get; set; }
        //使用Js管理多条link
        [MaxLength(500)]
        public string Links { get; set; }

        [MaxLength(500)]
        public string Experience { get; set; }
        [MaxLength(500)]
        public string DisLikes { get; set; }

        [MaxLength(1000)]
        public string NodeLayoutJson { get; set; }

        public DateTime DateCreated { get; set; }
        public DateTime? DateLastLogin { get; set; }
        public DateTime? DateLastPasswordChange { get; set; }

        public bool EmailQuestionPostReply { get; set; }
        public bool EmailQuestionReplyRelated { get; set; }
        public bool EmailResourcePostReply { get; set; }
        public bool EmailResourceReplyRelated { get; set; }
        public bool EmailCatterPostReply { get; set; }
        public bool EmailCatterReplyRelated { get; set; }

        public virtual ICollection<RelaUserUser> InterUsers { get; set; }
        public virtual ICollection<RelaUserUser> BeInterUsers { get; set; }
        public virtual ICollection<RelaUserTech> InterTechs { get; set; }
        //显而易见的事情没有打分、评价、描述的必要，因为比较、排行信息的获取代价不大。
        public virtual ICollection<RelaUserSite> InterSites { get; set; }

        public virtual ICollection<Chat> PostChats { get; set; }
        public virtual ICollection<Answer> PostAnswers { get; set; }
        public virtual ICollection<Question> PostQuestions { get; set; }
        public virtual ICollection<Resource> PostResources { get; set; }
        public virtual ICollection<Reply> Replys { get; set; }

    }
}
